package main;

import com.yuewen.mall.common.redisclient.RedisClient;
import jdk.nashorn.internal.ir.debug.JSONWriter;

import java.sql.Timestamp;
import java.util.*;

/**
 * Created by liwei.b on 2016/6/15.
 */
public class test {

    public static void main(String args[]) {
        testListObject();

//        long counter = 0;
//        for (int i = 0; i <= 9999; i++) {
//            Timestamp start = new Timestamp(new Date().getTime());
//            testListObject();
//            Timestamp end = new Timestamp(new Date().getTime());
//            long count = end.getTime() - start.getTime();
//            System.out.println(String.format("No.%d, %d",i+1, count));
//            try {
//                Thread.sleep(50);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }
        System.out.println("hi");
    }


    static void delete() {
        RedisClient client = new RedisClient("10.97.19.93", 6379);
        System.out.println(client.delete("AAAA"));
    }

    static void getByKey() {
        RedisClient client = new RedisClient("10.97.19.93", 6379);
        Object obj = client.get(Object.class, "AAAA");
    }

    static void testObject() {
        RedisClient client = new RedisClient("10.97.19.93", 6379);
        User u = new User();
        u.setName("francis");
        u.setNo(123);
        client.setObject("AAAA", u);
        User tmp = client.get(User.class, "AAAA");
    }

    static void testListObject() {
        RedisClient client = new RedisClient("10.97.19.93", 6379,"Yuewenmall@2016");
        User u = new User();
        u.setName("francis");
        u.setNo(123);
        User u1 = new User();
        u1.setName("francis");
        u1.setNo(123);
        List<User> users = new ArrayList<User>();
        users.add(u);
        users.add(u1);
        client.setObject("AAAA", users);
        List<User> tmp = client.get(new ArrayList<User>() {
        }.getClass(), "AAAA");

//        System.out.println(tmp.size());
    }

    static void testMapObject() {
        RedisClient client = new RedisClient("10.97.19.93", 6379);
        User u = new User();
        u.setName("francis");
        u.setNo(123);

        Map<String, User> map = new HashMap<String, User>();
        map.put("AAA", u);
        map.put("BBB", u);

        client.setObject("AAAA", map);
        Map<String, User> tmp = client.get(new HashMap<String, User>() {
        }.getClass(), "AAAA");

        System.out.println(tmp.size());
    }

    static void testComplexMapObject() {
        RedisClient client = new RedisClient("10.97.19.93", 6379);
        User u = new User();
        u.setName("francis");
        u.setNo(123);
        User mate = new User();
        mate.setNo(123);
        mate.setName("jiaji");
        u.setMate(mate);

        User u1 = new User();
        u1.setName("francis");
        u1.setNo(123);
        List<User> users = new ArrayList<User>();
        users.add(u);
        users.add(u1);

        Map<String, List<User>> map = new HashMap<String, List<User>>();
        map.put("AAA", users);
        map.put("BBB", users);

        client.setObject("AAAA", map);
        Map<String, List<User>> tmp = client.get(new HashMap<String, List<User>>() {
        }.getClass(), "AAAA");

        System.out.println(tmp.size());
    }
}
